home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / BaseShp.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  10.6 KB  |  347 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                BaseShp.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef BASESHP_H
  13. #define BASESHP_H
  14.  
  15. #ifndef CONSTANT_H
  16. #include "Constant.h"
  17. #endif
  18.  
  19. #ifndef FWSELECT_H
  20. #include "FWSelect.h"
  21. #endif
  22.  
  23. #ifndef FWSCPTBL_H
  24. #include "FWScptbl.h"
  25. #endif
  26.  
  27. #ifndef FWPAT_H
  28. #include "FWPat.h"
  29. #endif
  30.  
  31. #ifndef FWINK_H
  32. #include "FWInk.h"
  33. #endif
  34.  
  35. #ifndef FWSTYLE_H
  36. #include "FWStyle.h"
  37. #endif
  38.  
  39. #ifndef FWPOINT_H
  40. #include "FWPoint.h"
  41. #endif
  42.  
  43. #ifndef FWRECT_H
  44. #include "FWRect.h"
  45. #endif
  46.  
  47. #ifndef FWRUNTYP_H
  48. #include "FWRunTyp.h"
  49. #endif
  50.  
  51. #ifndef FWTCOLL_H
  52. #include "FWTColl.h"
  53. #endif
  54.  
  55. //========================================================================================
  56. // Forward Declarations
  57. //========================================================================================
  58.  
  59. class ODFacet;
  60. class ODShape;
  61. class CDrawPart;
  62. class CDrawPublishLink;
  63. class CDrawSubscribeLink;
  64. class FW_CGraphicContext;
  65. class FW_CMouseEvent;
  66. class FW_CRectShape;
  67. class FW_CPromise;
  68. class CDrawFacetClipper;
  69. class CDrawFrame;
  70. class FW_CView;
  71.  
  72. //========================================================================================
  73. // Constants
  74. //========================================================================================
  75.  
  76. enum ShapeType {
  77.     kLineShape = 1,
  78.     kRectShape = 2,
  79.     kOvalShape = 3,
  80.     kRRectShape = 4,
  81.     kTextShape = 5,
  82.     kProxyShape = 6,
  83.     kGroupShape = 7
  84. };
  85.  
  86. //========================================================================================
  87. // Global Methods
  88. //========================================================================================
  89.  
  90. inline FW_Fixed CalcHandlePenSize(FW_Fixed zoomFactor)
  91. {
  92.     return (FW_kFixedPos2 + FW_ODFixedToFixed(0x00008000)) / zoomFactor;
  93. }
  94.  
  95. //========================================================================================
  96. // class CBaseShape
  97. //========================================================================================
  98.  
  99. class CBaseShape : public FW_MScriptable
  100. {
  101. public:
  102.     FW_DECLARE_CLASS
  103.     FW_DECLARE_AUTO(CBaseShape)
  104.  
  105. public:
  106.     virtual ~CBaseShape();
  107.  
  108.     virtual void        Removed(Environment* ev);
  109.     virtual void        Deleted(Environment* ev);
  110.     
  111.     // ----- Drawing -----
  112.     void                Invalidate(Environment* ev);
  113.     virtual void         RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc) = 0;
  114.     void                RenderHandles(FW_CGraphicContext& gc, FW_Fixed zoomFactor);
  115.     void                InvalidateHandles(Environment* ev, FW_CView* contentView, ODShape* workingShape, FW_Fixed penSize);
  116.     
  117.     // ----- Shape setting -----
  118.     FW_Fixed            GetPenSize() const;
  119.         
  120.     // ----- Selection -----
  121.     virtual FW_Boolean    HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const = 0;
  122.     FW_Boolean            InSelectionRect(const FW_CRect& rect) const;
  123.     
  124.     short                WhichHandle(FW_CGraphicContext& gc, const FW_CPoint& mouse, FW_Fixed zoomFactor) const;
  125.     
  126.     void                 CalcHandle(short whichHandle, FW_CRectShape* handle, FW_Fixed penSize) const;
  127.     void                CalcHandle(short whichHandle, FW_CRect& rect, FW_Fixed penSize) const;
  128.  
  129.     virtual void        SelectShape(Environment *ev, FW_Boolean state);
  130.     FW_Boolean            IsSelectedShape() const
  131.                             {return fSelected;}
  132.  
  133.     virtual void        RestoreShape(Environment *ev);
  134.     
  135.     // ----- Creation -----
  136.     virtual void         TrackFeedback(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc, const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint, FW_Boolean erase);
  137.     virtual void         SetShapeGeometry(const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint) = 0;
  138.  
  139.     // ----- Promises -----
  140.     void                Promised(FW_StorageKinds storageKind, FW_Boolean state);
  141.     FW_Boolean            IsPromised() const
  142.                             {return fPromised != 0;}
  143.     void                 CheckPromise(Environment* ev);
  144.  
  145.     // ----- Drag -----
  146.     virtual void        OffsetShape(Environment *ev, FW_Fixed xDelta, FW_Fixed yDelta) = 0;
  147.     
  148.     // ----- Resize -----
  149.     FW_CStyle            GetResizeStyle() const;
  150.     virtual void        ResizeFeedback(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, 
  151.                                         short whichHandle, const FW_CPoint& mouseLoc) = 0;
  152.     virtual void        GetMapRects(short whichHandle, const FW_CPoint& lastLocation,
  153.                                     FW_CRect& srcRect, FW_CRect& dstRect) = 0;
  154.     virtual void        GetHandleCenter(short whichHandle, FW_CPoint& center) const = 0;
  155.     virtual void        MapShape(Environment *ev, const FW_CRect& srcRect, const FW_CRect& dstRect) = 0;
  156.     
  157.     void                GetUpdateBox(Environment* ev, ODShape *updateBox) const;
  158.     void                GetUpdateBox(FW_CRect& updateBox) const;
  159.     void                GetDragRect(FW_CRect& dragRect) const;
  160.     
  161.     virtual ODShape*    CreateShapeOutline(Environment *ev) = 0;
  162.     virtual ODShape*    AcquireClipShape(Environment* ev);
  163.     virtual ODShape*    CalcClipShape(Environment* ev) = 0;
  164.     virtual FW_CRect    GetRectGeometry() const = 0;
  165.     
  166.     virtual void        SubtractToWorkingClip(Environment *ev, 
  167.                                             CDrawFacetClipper* facetClipper, 
  168.                                             ODFacet* containingFacet, 
  169.                                             ODShape* workingClip,
  170.                                             ODShape* tempShape,
  171.                                             ODShape* limitShape);
  172.     
  173.     // ----- z-Order -----
  174.     virtual void         MovedAfter(Environment* ev, CBaseShape* shape);
  175.     virtual void         MovedBefore(Environment* ev, CBaseShape* shape);
  176.     virtual void         MovedFirst(Environment* ev);
  177.     virtual void         MovedLast(Environment* ev);
  178.     
  179.     // ----- Persistence -----
  180.     virtual void         Flatten(FW_CWritableStream& archive);
  181.     
  182.     // ----- Cache -----
  183.     void                ClearCache(Environment* ev);
  184.     
  185.     // ----- Linking -----
  186.     virtual void        SetPublishLink(Environment* ev, 
  187.                             CDrawPublishLink* publishLink);
  188.     CDrawPublishLink*    GetPublishLink() const
  189.                             {return fPublishLink;}
  190.     FW_Boolean            IsPublished() const
  191.                             {return fPublishLink != NULL;}
  192.                             
  193.     virtual void        SetSubscribeLink(Environment* ev, 
  194.                             CDrawSubscribeLink* subscribeLink);
  195.     CDrawSubscribeLink*    GetSubscribeLink() const
  196.                             {return fSubscribeLink;}
  197.     FW_Boolean            IsSubscribed() const
  198.                             {return fSubscribeLink != NULL;}
  199.     virtual FW_Boolean    IsInLinkDestination(Environment* ev);
  200.                             
  201.     short                GetExternalizationIndex()
  202.                             { return fExternalizationIndex; }
  203.     void                SetExternalizationIndex(short index)
  204.                             { fExternalizationIndex = index; }
  205.                             
  206.     // ----- Getters/Setters -----
  207.     virtual FW_Boolean    SetFrozen(FW_Boolean state);
  208.     virtual FW_Boolean IsFrozen() const;
  209.     
  210.     FW_Boolean            HasFillStyle() const
  211.                             {return (fRenderVerb & kFillOnly) != 0;}
  212.     FW_Boolean            FillOnly() const
  213.                             {return fRenderVerb == kFillOnly;}
  214.     FW_Boolean            HasFrameStyle() const
  215.                             {return (fRenderVerb & kFrameOnly) != 0;}
  216.     FW_Boolean            FrameOnly() const
  217.                             {return fRenderVerb == kFrameOnly;}
  218.     FW_Boolean            HasFrameAndFillStyle() const
  219.                             {return (fRenderVerb == kFillFrame);}
  220.                                                         
  221.     void                GetColor(FW_Boolean fill, FW_CColor& color);
  222.     FW_CPattern            GetPattern(FW_Boolean fill);
  223.     unsigned short        GetRenderVerb()
  224.                             { return fRenderVerb; };
  225.                         
  226.     short                GetNumberOfHandles() const
  227.                             {return fNumberOfHandles;}
  228.     ShapeType            GetShapeType() const
  229.                             {return (ShapeType)fShapeType;}
  230.     
  231.     void                SetFrameInk(const FW_CInk& ink)
  232.                             {fFrameInk = ink;}
  233.     void                SetFrameStyle(const FW_CStyle& style)
  234.                             {fFrameStyle = style;}
  235.     void                SetFillInk(const FW_CInk& ink)
  236.                             {fFillInk = ink;}
  237.     void                SetFillStyle(const FW_CStyle& style)
  238.                             {fFillStyle = style;}
  239.     
  240.     virtual void        ChangeFrameColor(Environment* ev, const FW_CColor& color);
  241.     virtual void        ChangeFramePattern(Environment* ev, const FW_CPattern& pattern);
  242.  
  243.     virtual void        ChangeFillColor(Environment* ev, const FW_CColor& color);
  244.     virtual void        ChangeFillPattern(Environment* ev, const FW_CPattern& pattern);
  245.  
  246.     virtual void        ChangePenSize(Environment* ev, FW_Fixed newPenSize);
  247.     virtual void        ChangeRenderVerb(Environment* ev, unsigned short renderVerb);
  248.  
  249.     FW_CInk                UnshareInk(const FW_CInk& ink) const;
  250.     FW_CStyle            UnshareStyle(const FW_CStyle& style) const;
  251.     
  252.     virtual void        AdjustRectForPenSize(FW_CRect& rect, FW_Fixed penSize) const;
  253.  
  254.     // ----- Semantic Object -----
  255.     
  256.     virtual ODDescType    GetObjectClass() const;
  257.     
  258.     virtual FW_Boolean    HasProperty(ODDescType whichProperty) const;
  259.     
  260.     virtual FW_Boolean    GetProperty(Environment* ev, 
  261.                                     FW_CPart* part, 
  262.                                     FW_CDesc& propertyValue, 
  263.                                     ODDescType whichProperty, 
  264.                                     ODDescType desiredType) const;
  265.                                     
  266.     virtual void        SetProperty(Environment* ev, 
  267.                                     FW_CPart* part, 
  268.                                     FW_CDesc& propertyValue, 
  269.                                     ODDescType whichProperty);    
  270.                                                         
  271.     virtual void        GetUndoStrings(Environment* ev,
  272.                                     FW_CPart* part,
  273.                                     ODDescType whichProperty, 
  274.                                     FW_CString& undoString, 
  275.                                     FW_CString& redoString) const;
  276.     
  277.     // ----- Purge -----
  278.     virtual void        MakePurgeable(Environment* ev, CDrawFrame* drawFrame, const FW_CRect& bounds);
  279.     
  280.     // ----- Archiving -----
  281.     static void*         Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  282.     static void         Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object);
  283.  
  284. protected:
  285.     CBaseShape(CDrawPart* drawPart, short numberOfHandles, unsigned short shapeType, unsigned short renderVerb);
  286.     CBaseShape(CDrawPart* drawPart, FW_CReadableStream& archive);
  287.     
  288.     void                 InitStatic();
  289.     
  290. public:        
  291.     static FW_CRectShape*                gWorkingHandle;
  292.     static unsigned long                 gShapeCount;
  293.  
  294. protected:
  295.     CDrawPart*                            fDrawPart;
  296.     unsigned short                        fPromised;
  297.     
  298.     FW_CInk                                fFrameInk;
  299.     FW_CInk                                fFillInk;
  300.     FW_CStyle                            fFrameStyle;
  301.     FW_CStyle                            fFillStyle;
  302.     
  303.     unsigned short                        fRenderVerb;
  304.  
  305.     unsigned short                        fShapeType;
  306.     
  307.     FW_Boolean                            fSelected;
  308.     short                                fNumberOfHandles;
  309.     CDrawPublishLink*                    fPublishLink;
  310.     CDrawSubscribeLink*                    fSubscribeLink;
  311.     short                                fExternalizationIndex;    // used by links to identify their shapes
  312.     
  313.     ODShape*                            fClipShape;
  314. };
  315.  
  316. //========================================================================================
  317. // class CShapeCollection
  318. //========================================================================================
  319.  
  320. class CShapeCollection : public FW_TOrderedCollection<CBaseShape>
  321. {
  322. public:
  323.     FW_DECLARE_AUTO(CShapeCollection)
  324.     
  325.     CShapeCollection() :
  326.         FW_TOrderedCollection<CBaseShape>(){}
  327.     ~CShapeCollection() {}
  328. };
  329.  
  330.  
  331.  
  332. //========================================================================================
  333. // class CShapeCollectionIterator
  334. //========================================================================================
  335.  
  336. class CShapeCollectionIterator : public FW_TOrderedCollectionIterator<CBaseShape>
  337. {
  338. public:
  339.     FW_DECLARE_AUTO(CShapeCollectionIterator)
  340.     
  341.     CShapeCollectionIterator(CShapeCollection* collection) :
  342.         FW_TOrderedCollectionIterator<CBaseShape>(collection){}
  343.     ~CShapeCollectionIterator() {}
  344. };
  345.  
  346. #endif
  347.